/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TestingDialog.java
 *
 * Created on 25.01.2009, 18:11:14
 */
package trim.gui.testing;

import java.util.List;
import trim.Trim;
import trim.common.inputdata.InputData;
import trim.common.result.TrimResult;
import trim.gui.testing.models.ResultListTableModel;
import trim.gui.testing.objects.ResultsListItem;

/**
 *
 * @author Дмитрий
 */
public class TestingDialog extends javax.swing.JDialog
{

  private ResultListTableModel resultListTableModel;

  /** Creates new form TestingDialog */
  public TestingDialog(java.awt.Frame parent,boolean modal,ResultListTableModel resultListTableModel)
  {
    super(parent,modal);
    this.resultListTableModel=resultListTableModel;
    initComponents();

  }

  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jSpinnerMinFormats = new javax.swing.JSpinner();
    jSpinnerMaxFormatCount = new javax.swing.JSpinner();
    jSpinnerMinMaterials = new javax.swing.JSpinner();
    jSpinnerTestsPerSettings = new javax.swing.JSpinner();
    jLabel9 = new javax.swing.JLabel();
    jLabel10 = new javax.swing.JLabel();
    jLabel11 = new javax.swing.JLabel();
    jLabel12 = new javax.swing.JLabel();
    jSpinnerMaxMaterialCount = new javax.swing.JSpinner();
    jSpinnerMaxFormats = new javax.swing.JSpinner();
    jSpinnerMaxMaterials = new javax.swing.JSpinner();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
    jLabel1.setText("Различных форматов:");

    jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11));
    jLabel2.setText("Количество одного формата:");

    jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
    jLabel3.setText("Различных материалов:");

    jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11));
    jLabel4.setText("Кол-во тестов для каждой настройки:");

    jLabel6.setFont(new java.awt.Font("Monospaced", 1, 11));
    jLabel6.setText("max");

    jLabel7.setFont(new java.awt.Font("Monospaced", 1, 11));
    jLabel7.setText("min");

    jLabel8.setFont(new java.awt.Font("Monospaced", 1, 11));
    jLabel8.setText("min");

    jSpinnerMinFormats.setValue(10);

    jSpinnerMaxFormatCount.setValue(100);

    jSpinnerMinMaterials.setValue(1);

    jSpinnerTestsPerSettings.setValue(1);

    jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11));
    jLabel9.setText("Количество одного материала:");

    jLabel10.setFont(new java.awt.Font("Monospaced", 1, 11));
    jLabel10.setText("max");

    jLabel11.setFont(new java.awt.Font("Monospaced", 1, 11));
    jLabel11.setText("max");

    jLabel12.setFont(new java.awt.Font("Monospaced", 1, 11));
    jLabel12.setText("max");

    jSpinnerMaxMaterialCount.setValue(1);

    jSpinnerMaxFormats.setValue(10);

    jSpinnerMaxMaterials.setValue(1);

    jButton1.setFont(new java.awt.Font("Tahoma", 1, 11));
    jButton1.setText("Запуск тестирования");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });

    jButton2.setFont(new java.awt.Font("Tahoma", 1, 11));
    jButton2.setText("Закрыть");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jLabel3)
              .addComponent(jLabel2)
              .addComponent(jLabel1)
              .addComponent(jLabel9))
            .addGap(43, 43, 43)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSpinnerMinFormats, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSpinnerMaxFormats, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSpinnerMaxFormatCount, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE))
              .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSpinnerMinMaterials, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSpinnerMaxMaterials, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
              .addGroup(layout.createSequentialGroup()
                .addComponent(jLabel12)
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addComponent(jSpinnerTestsPerSettings, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                  .addComponent(jSpinnerMaxMaterialCount, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)))))
          .addComponent(jLabel4)
          .addGroup(layout.createSequentialGroup()
            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)))
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel1)
          .addComponent(jLabel7)
          .addComponent(jSpinnerMinFormats, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jSpinnerMaxFormats, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel10))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel2)
          .addComponent(jLabel6)
          .addComponent(jSpinnerMaxFormatCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel3)
          .addComponent(jLabel8)
          .addComponent(jSpinnerMinMaterials, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jSpinnerMaxMaterials, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel11))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
            .addComponent(jLabel9)
            .addComponent(jLabel12))
          .addComponent(jSpinnerMaxMaterialCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jLabel4)
          .addComponent(jSpinnerTestsPerSettings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jButton1)
          .addComponent(jButton2))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
    {//GEN-HEADEREND:event_jButton2ActionPerformed
      setVisible(false);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed
      Integer minFormats=(Integer)jSpinnerMinFormats.getValue();
      Integer maxFormats=(Integer)jSpinnerMaxFormats.getValue();
      Integer maxFormatCount=(Integer)jSpinnerMaxFormatCount.getValue();
      Integer minMaterials=(Integer)jSpinnerMinMaterials.getValue();
      Integer maxMaterials=(Integer)jSpinnerMaxMaterials.getValue();
      Integer maxMaterialCount=(Integer)jSpinnerMaxMaterialCount.getValue();
      Integer n=(Integer)jSpinnerTestsPerSettings.getValue();

      List<InputData> tests=new TestsGenerator().generateTests(minFormats,maxFormats,maxFormatCount,
          minMaterials,maxMaterials,maxMaterialCount,n);
      List<Trim> lm=AppState.getPlaginManager().getUsedMethods();
      TestsRunner tr=new TestsRunner(tests,lm);
      tr.addListener(new TestRunnerListener()
      {

        public void newResultEvent(InputData inputData,TrimResult tr,Trim method,long time)
        {
          resultListTableModel.addResult(new ResultsListItem(tr,method,inputData.clone(),time));
        }
      });
      tr.startTests();
    }//GEN-LAST:event_jButton1ActionPerformed
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel10;
  private javax.swing.JLabel jLabel11;
  private javax.swing.JLabel jLabel12;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JLabel jLabel4;
  private javax.swing.JLabel jLabel6;
  private javax.swing.JLabel jLabel7;
  private javax.swing.JLabel jLabel8;
  private javax.swing.JLabel jLabel9;
  private javax.swing.JSpinner jSpinnerMaxFormatCount;
  private javax.swing.JSpinner jSpinnerMaxFormats;
  private javax.swing.JSpinner jSpinnerMaxMaterialCount;
  private javax.swing.JSpinner jSpinnerMaxMaterials;
  private javax.swing.JSpinner jSpinnerMinFormats;
  private javax.swing.JSpinner jSpinnerMinMaterials;
  private javax.swing.JSpinner jSpinnerTestsPerSettings;
  // End of variables declaration//GEN-END:variables
}
